﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Discovery;
using System.ServiceModel.Channels;

namespace Devtm.ServiceModel.Discovery
{
    
    public static class DiscoveryHelper
    {


        /// <summary>
        /// Add announcement process on service
        /// </summary>
        /// <param name="service"></param>
        /// <param name="binding"></param>
        /// <param name="announcementEndpointAddress"></param>
        public static void AddAnnouncement(this ServiceHost service, Binding binding, Uri announcementEndpointAddress)
        {

            // Create an announcement endpoint, which points to the Announcement Endpoint hosted by the proxy service.
            AnnouncementEndpoint announcementEndpoint = new AnnouncementEndpoint(binding, new EndpointAddress(announcementEndpointAddress));

            // Create a ServiceDiscoveryBehavior and add the announcement endpoint
            ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();
            serviceDiscoveryBehavior.AnnouncementEndpoints.Add(announcementEndpoint);

            // Add the ServiceDiscoveryBehavior to the service host to make the service discoverable
            service.Description.Behaviors.Add(serviceDiscoveryBehavior);


        }

        /// <summary>
        /// Add announcement process on service
        /// </summary>
        /// <param name="service"></param>
        /// <param name="announcementEndpointAddress"></param>
        public static void AddAnnouncement(this ServiceHost service, Uri announcementEndpointAddress)
        {
            service.AddAnnouncement(new NetTcpBinding(), announcementEndpointAddress);
        }


    }
}
